package org.shop.util;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;

public class ObjUtil {

	/**
	 * 判断对象或对象数组中每一个对象是否为空: 对象为null，字符序列长度为0，集合类、Map为empty
	 * 
	 * @param obj
	 * @return
	 */
	public static boolean isNullOrEmpty(Object obj) {
		if (obj == null)
			return true;

		if (obj instanceof CharSequence)
			return ((CharSequence) obj).length() == 0;

		if (obj instanceof Collection)
			return ((Collection) obj).isEmpty();

		if (obj instanceof Map)
			return ((Map) obj).isEmpty();

		if(obj.getClass().isArray()) {
			  return Array.getLength(obj) == 0;
		}
		return false;
	}
	
	public static boolean isNotNullAndEmpty(Object obj) {
		return !isNullOrEmpty(obj);
	}

}
